#include "UdpDataPacket.h"

using namespace clusnet::net;

UdpDataPacket::UdpDataPacket()
    : data_()
{
}

UdpDataPacket::UdpDataPacket(size_t dataLength)
    : data_(dataLength)
{
    assert(dataLength <= maxLength());
}

UdpDataPacket::~UdpDataPacket()
{
}

UdpDataPacket::UdpDataPacket(UdpDataPacket&& that)
    : data_(std::move(that.data_))
{
}

UdpDataPacket& UdpDataPacket::operator= (UdpDataPacket&& that)
{
    if (this == &that)
    {
        return *this;
    }

    data_ = std::move(that.data_);
    return *this;
}

void UdpDataPacket::append(char const* buf, size_t len)
{
    len = std::min(maxLength(), data_.length() + len);
    data_.append(buf, len);
}
